using System;

namespace umbSearch.businessLogic
{
	/// <summary>
	/// Summary description for SearchUpdateActionHandler.
	/// </summary>
	public class SearchUpdateActionHandler : umbraco.BusinessLogic.Actions.IActionHandler
	{
		public SearchUpdateActionHandler()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#region IActionHandler Members

		public string HandlerName()
		{
			return "umbSearchUpdate";
		}

		public bool Execute(umbraco.cms.businesslogic.web.Document documentObject, umbraco.interfaces.IAction action)
		{
			if (action.Alias == new umbraco.BusinessLogic.Actions.ActionDelete().Alias || action.Alias == new umbraco.BusinessLogic.Actions.ActionUnPublish().Alias) 
			{
				Indexer.DeleteFromIndex(documentObject.Id);
				umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.System, new umbraco.BusinessLogic.User(0), documentObject.Id, "Removed from Lucene search index");
			} 
			else 
			{
				Indexer.AddPageToIndex(documentObject.Id);
				umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.System, new umbraco.BusinessLogic.User(0), documentObject.Id, "Added to Lucene search index");
			}
			return true;
		}

		public umbraco.interfaces.IAction[] ReturnActions()
		{
			// TODO:  Add SearchUpdateActionHandler.ReturnActions implementation
			umbraco.interfaces.IAction[] _retVal = {new umbraco.BusinessLogic.Actions.ActionPublish(), new umbraco.BusinessLogic.Actions.ActionUnPublish(), new umbraco.BusinessLogic.Actions.ActionMove(), new umbraco.BusinessLogic.Actions.ActionDelete()};
			return _retVal;
		}

		#endregion
	}
}
